var express = require("express");
var router = express.Router();
const Result = require("../utils/result");
const goodsConversionService = require("../services/goodsConversionService");

//创建兑换记录
router.get('/add',async function(req,res){
    const {userId,goodsId,score,useDay,title} = req.query;
    await goodsConversionService.add(userId,goodsId,score,useDay,title);
    res.json(Result.success());
})

//使用商品好礼
router.get('/use',async function(req,res){
    const {userId,goodsId} = req.query;
    await goodsConversionService.useGift(userId,goodsId);
    res.json(Result.success());
});

//获取商品好礼列表
router.get('/list',async function(req,res){
    const userId = req.query.userId;
    const {unusedArr,usedArr,pastArr} = await goodsConversionService.getList(userId);
    res.json(Result.success({unusedArr,usedArr,pastArr}))
})

module.exports = router;